﻿using SocialCee.ExternalSystems.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;

namespace SocialCee.ExternalSystems.Loader
{
    [Export(typeof(IExternalSystemsFactory))]
    public class ExtSystemFactory : IExternalSystemsFactory
    {
        [ImportMany]
        IEnumerable<Lazy<IClient, IClientName>> MediaClients;

        public IClient Get(string name)
        {
            foreach (Lazy<IClient, IClientName> i in MediaClients)
            {
                if (i.Metadata.UniqueName.Equals(name)) return i.Value;
            }

            return null;
        }

        public List<string> GetClientNames()
        {
            List<string> names = new List<string>();

            foreach (Lazy<IClient, IClientName> i in MediaClients)
                names.Add(i.Metadata.UniqueName);

            return names;
        }

        public Dictionary<string, IClient> GetClients()
        {
            Dictionary<string, IClient> clients = new Dictionary<string, IClient>();

            foreach (Lazy<IClient, IClientName> i in MediaClients)
                clients.Add(i.Metadata.UniqueName, i.Value);

            return clients;
        }
    }
}
